﻿using System;
using System.Text;
using Microsoft.VisualStudio.TextTemplating.VSHost;
using Mnow.MvvmLight.Tools.ViewModelDiagram.CustomCode.CodeGeneration;
using System.IO;

namespace Mnow.MvvmLight.Tools.ViewModelDiagram
{
    [global::System.Runtime.InteropServices.Guid("EE55ED30-88FE-4AE1-8487-73F5324DBF95")]
    public class CodeGenerator : TemplatedCodeGenerator
    {
        protected override byte[] GenerateCode(string inputFileName, string inputFileContent)
        {
            inputFileContent = ASCIIEncoding.UTF8.GetString(CodeGenerationResource.vmcd);
            FileInfo fi = new FileInfo(inputFileName);
            inputFileContent = inputFileContent.Replace("$safeitemname$.vmcd", fi.Name);
            byte[] data; 
            data = base.GenerateCode(inputFileName, inputFileContent); 
            byte[] ascii = new byte[data.Length - 3]; 
            Array.Copy(data, 3, ascii, 0, data.Length - 3); 
            return ascii; 
        }
    }
}
